import java.lang.*;

public class hw2 
{
	//T = O(n)
	private void subProblemOne(Integer[] iterationTime)
	{
		for(int iter = 0; iter<3; iter++)
		{
			   long start = System.currentTimeMillis();
			    /*do something*/
			   double sum = 0;
			   double delta = 0.00001;
			   
			   for(int i=0; i< iterationTime[iter]; i++)
			   {
			       sum += delta;
			   }
			   
			   long end = System.currentTimeMillis();
			
			   long timeElapsed = end - start;   
			   System.out.println("sub1[" + iter + "] --> " + timeElapsed +" ms");
			}
	}
	
	//T = O(n^2)
	private void subProblemTwo(Integer[] iterationTime)
	{
		for(int iter = 0; iter<3; iter++)
		{
			   long start = System.currentTimeMillis();
			    /*do something*/
			   double sum = 0;
			   double delta = 0.00001;
			   
			   for(int i=0; i< iterationTime[iter]; i++)
			   {
				   for (int j = 0; j < iterationTime[iter]; j++)
				   {
					   sum += delta;
				   }
			   }
			   
			   long end = System.currentTimeMillis();
			
			   long timeElapsed = end - start;   
			   System.out.println("sub2[" + iter + "] --> " + timeElapsed +" ms");
			}
	}
	
	//T = O(N^3)
	private void subProblemThree(Integer[] iterationTime)
	{
		for(int iter = 0; iter<3; iter++)
		{
			   long start = System.currentTimeMillis();
			    /*do something*/
			   double sum = 0;
			   double delta = 0.00001;
			   
			   for(int i=0; i< iterationTime[iter]; i++)
			   {
				   for (int j = 0; j < iterationTime[iter] * iterationTime[iter]; j++)
				   {
					   sum += delta;
				   }
			   }
			   
			   long end = System.currentTimeMillis();
			
			   long timeElapsed = end - start;   
			   System.out.println("sub3[" + iter + "] --> " + timeElapsed +" ms");
			}
	}
	
	//T = O(N^2)
	private void subProblemFour(Integer[] iterationTime)
	{
		for(int iter = 0; iter<3; iter++)
		{
			   long start = System.currentTimeMillis();
			    /*do something*/
			   double sum = 0;
			   double delta = 0.00001;
			   
			   for(int i=0; i< iterationTime[iter]; i++)
			   {
				   for (int j = 0; j < i; j++)
				   {
					   sum += delta;
				   }
			   }
			   
			   long end = System.currentTimeMillis();
			
			   long timeElapsed = end - start;   
			   System.out.println("sub4[" + iter + "] --> " + timeElapsed +" ms");
			}
	}
	
	//T = O(N^5)
	private void subProblemFive(Integer[] iterationTime)
	{
		for(int iter = 0; iter<3; iter++)
		{
			   long start = System.currentTimeMillis();
			    /*do something*/
			   double sum = 0;
			   double delta = 0.00001;
			   
			   for(int i=0; i< iterationTime[iter]; i++)
			   {
				   for (int j = 0; j < i * i; j++)
				   {
					   for (int k = 0; k < j; k++)
					   {
						   sum += delta;
					   }
				   }
			   }
			   
			   long end = System.currentTimeMillis();
			
			   long timeElapsed = end - start;   
			   System.out.println("sub5[" + iter + "] --> " + timeElapsed +" ms");
			}
	}
	
	//T = O(N^4)
	private void subProblemSix(Integer[] iterationTime)
	{
		for(int iter = 0; iter<3; iter++)
		{
			   long start = System.currentTimeMillis();
			    /*do something*/
			   double sum = 0;
			   double delta = 0.00001;
			   
			   for(int i=0; i< iterationTime[iter]; i++)
			   {
				   for (int j = 0; j < i * i; j++)
				   {
					   if (j % i == 0)
					   {
						   for (int k = 0; k < j; k++)
						   {
							   sum += delta;
						   }
					   }
				   }
			   }
			   
			   long end = System.currentTimeMillis();
			
			   long timeElapsed = end - start;   
			   System.out.println("sub6[" + iter + "] --> " + timeElapsed +" ms");
			}
	}
	
	static public void main(String args[])
	{
		Integer iterationTimeOne[] = {10000, 100000, 1000000};
		Integer iterationTimeTwo[] = {100, 1000, 10000};
		Integer iterationTimeThree[] = {10, 100, 1000};
		Integer iterationTimeFour[] = {1000, 10000, 10000};
		Integer iterationTimeFive[] = {1, 10, 100};
		Integer iterationTimeSix[] = {1, 10, 100};
		
		hw2 toy = new hw2();
		
		toy.subProblemOne(iterationTimeOne);
		toy.subProblemTwo(iterationTimeTwo);
		toy.subProblemThree(iterationTimeThree);
		toy.subProblemFour(iterationTimeFour);
		toy.subProblemFive(iterationTimeFive);
		toy.subProblemSix(iterationTimeSix);
	}
}
